package br.com.ffm.praticas.facade;

import java.sql.SQLException;
import java.util.List;

import br.com.ffm.praticas.bean.State;
import br.com.ffm.praticas.dao.StateDAO;

public class StateFACADE {
	
	private static StateFACADE stateFacade;
	private static StateDAO stateDAO;
	
	private StateFACADE(){
		stateDAO = new StateDAO();
	}
	
	/**
	 * Method that create and returns an unique instance of StateFACADE
	 * @return An instance of StateFACADE
	 */
	public static StateFACADE getInstance(){
		if(stateFacade == null){
			stateFacade = new StateFACADE();
		}
		return stateFacade;
	}
	
	/**
	 * Method that return all the States
	 * @return List<State>
	 * @throws SQLException
	 */
	public List<State> getStates() throws SQLException {
		return stateDAO.getStates();
	}
	
	/**
	 * Method that search a State by ID
	 * @param id The ID of the State to be found
	 * @return If found returns it, else returns null
	 * @throws SQLException 
	 */
	public State getState(int id) throws SQLException{
		return stateDAO.getState(id);
	}
	
	/**
	 * Method that search a State by Description
	 * @param description The Description of the State to be found
	 * @return If found returns it, else returns null
	 * @throws SQLException 
	 */
	public State getState(String description) throws SQLException{
		return stateDAO.getState(description);
	}
	
	/**
	 * Method that count the number of States
	 * @return The number of States
	 * @throws SQLException 
	 */
	public int count() throws SQLException{
		return stateDAO.getStates().size();
	}

}
